<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="链接名称">
        <el-input v-model="page.rname" placeholder="链接名称"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-input v-model="page.rname" placeholder="状态"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryAllRole">查询</el-button>
        <el-button type="success" @click="clear">重置</el-button>
        <el-button type="add" @click="clear">添加</el-button>
      </el-form-item>
    </el-form>
    <!--    弹出窗-->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%">
      <span>
        <el-tree
          ref="tree"
          :data="treeData"
          show-checkbox
          node-key="mid"
          default-expand-all
          :props="defaultProps">
</el-tree>
      </span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="updSubRole()">确 定</el-button>
  </span>
    </el-dialog>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="liandi"
        label="链接名称/链接地址">
      </el-table-column>
      <el-table-column
        prop="paixu"
        label="排序">
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态">
        <template slot-scope="scope">
          <el-switch
            style="display: block"
            v-model="scope.row.statusId"
            @change="handleChangeStatus(scope.row,scope.row.statusId)"
            :active-value="0"
            :inactive-value="1"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="正常"
            inactive-text="禁用">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index,scope.row)" v-has="'role:delete'">删除</el-button>
          <el-button type="text" @click="dialogVisible = true">修改</el-button>
          <el-dialog
            title="领课网络编辑"
            :visible.sync="dialogVisible"
            width="30%"
            :before-close="handleClose">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
              <el-form-item label="链接地址:">
                <el-input v-model="input" placeholder="请输入内容"></el-input>
              </el-form-item>
              <el-form-item label="链接标题:">
                <el-input v-model="input" placeholder="请输入内容"></el-input>
              </el-form-item>
              <el-form-item label="打开方式:">
                <el-radio v-model="radio" label="1">新窗口打开</el-radio>
                <el-radio v-model="radio" label="2">同窗口打开</el-radio>
              </el-form-item>
              <el-form-item label="排序">
                <el-input-number v-model="formInline.num" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
          </el-dialog>
        </template>
      </el-table-column>
    </el-table>
    <!--    分页插件-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.current"
      :page-sizes="[1,5, 10, 15, 20]"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total">
    </el-pagination>
  </div>
</template>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>

<script>
import qs from 'qs';
export default {
  methods: {
    handleChange(value) {
      console.log(value);
    },
    onSubmit() {
      console.log('submit!');
    },
    handleChangeStatus(obj,statusId){
      const title = { 1: '禁用', 0: '启用' }
      this.$confirm(`确定要${title[statusId]}吗?`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableData.statusId=obj.statusId
      }).catch(() => {
        obj.statusId=(statusId+1)%2
      })
    },
  },

  data() {
    return {
      dialogVisible: false,
      formInline: {
        num: '1',
      },
      radio: '1',
      tableData: [{
        id:'1',
        liandi:'领课网络',
        paixu:'1',
        status:'正常'
      }],


      page:{
        rname:"",
        current:1,//当前页
        size:10,//每页显示的条数
        total:0//总条数
      },
    }
  }
}
</script>
